package com.violet.springaop.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author LiChaochao
 * @Date 2021/10/21 10:08
 * @Description
 */
@Aspect
@Component
public class MyAspect {

    @Before("execution(public int com.violet.springaop.service.impl.CalcServiceImpl.*(..))")
    public void beforeNotify() {
        System.out.println("@Before……前置通知");
    }

    @After("execution(public int com.violet.springaop.service.impl.CalcServiceImpl.*(..))")
    public void afterNotify() {
        System.out.println("@After……后置通知");
    }

    @AfterReturning("execution(public int com.violet.springaop.service.impl.CalcServiceImpl.*(..))")
    public void afterReturningNotify() {
        System.out.println("@AfterReturning……返回后通知");
    }

    @AfterThrowing("execution(public int com.violet.springaop.service.impl.CalcServiceImpl.*(..))")
    public void afterThrowingNotify() {
        System.out.println("@AfterThrowing……异常通知");
    }

    @Around("execution(public int com.violet.springaop.service.impl.CalcServiceImpl.*(..))")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Object retValue = null;
        System.out.println("环绕通知之前");
        // 回到原来的方法处
        retValue = proceedingJoinPoint.proceed();
        System.out.println("环绕通知之后");
        return retValue;
    }

}
